const app = getApp();
let Charts = require('/utils/wxcharts-min.js');
import { jiatuiRequest, hbappRequest,zg99Request } from "/utils/requests";
const version = xhs.getSystemInfoSync().SDKVersion
Page({
  /**
   * 页面的初始数据
   */
  data: {
    // 必要参数：zwid：职位分析ID；actid：表单存放（zg99）ID；lx：项目类型；xm：本次活动名称；cont：控制台；listId、lists：切换；showIcon、isShowAuth：登录窗口；
    zwid: 27,
    actid: 21808,
    lx: 'sk',
    xm: 'sk',
    myPhone: '',
    // cont：控制选岗、小字部分、缴费人数、选岗后是否展示；open方法控制
    // 0 官方不发布数据；展示选岗、小字和缴费人数，选岗后展示选岗信息
    // 1 官方不发布数据；展示选岗、小字和缴费人数，选岗后不展示选岗信息
    // 2 官方发布数据、公布缴费人数；展示缴费人数；不展示选岗和小字
    // 3 官方发布数据、公布缴费人数；展示选岗和缴费人数；不展示小字，选岗后展示选岗信息
    // 4 官方发布数据、公布缴费人数；展示选岗和缴费人数；不展示小字，选岗后不展示选岗信息
    // 5 官方发布数据、不公布缴费人数；不展示选岗、缴费人数和小字
    // 6 官方发布数据、不公布缴费人数；展示选岗；不展示缴费人数和小字，选岗后展示选岗信息
    // 7 官方发布数据、不公布缴费人数；展示选岗；不展示缴费人数和小字，选岗后不展示选岗信息
    // 8 官方发布数据、公布报名人数、审核通过人数、不公布缴费人数；不展示选岗、缴费人数和小字
    // 9 官方发布数据、只公布缴费人数；不展示选岗、缴费人数和小字
    cont: 1,
    // bos报名人数或审核通过人数
    // 0 报名人数
    // 1 审核通过人数
    bos: 's',
    fir: 'bm',
    listId: 0,
    lists: [{
      'title': '数据一览',
      "zt": 'on'
    }, {
      'title': '数据查询',
      "zt": ''
    }, {
      'title': '职位收藏',
      "zt": ''
    }],
    showIcon: !0,
    isShowAuth: !1,
    isShowCdNav: !1,
    // 头图部分
    basic_data1: {
      banner: 'https://hb.offcn.com/zg/xcximg/bmsjfx/banner.jpg',
      banner1: 'https://hb.offcn.com/zg/xcximg/bmsjfx/banner1.jpg',
    },
    // 截止时间
    basic_data2: {
      lastTime: '5月25日',
      myhours: '14时',
    },
    lastTime: 0,
    // 当前总通过数、总缴费人数和总竞争比
    basic_data3: {
      tgs: 0,
      jfs: 0,
      agv_jzb: '0',
    },
    // 每日报名数据对比数据
    basic_data4: {
      categories: [],
      series: [{}]
    },
    // 职位收藏每日报名数据对比数据
    basic_data11: {
      categories: [],
      series: [{}]
    },
    // 数据查询每日报名数据对比数据
    basic_data12: {
      categories: [],
      series: [{}]
    },
    // 报名人数最多职位
    basic_data5: {
      bmzdgw: []
    },
    // 竞争最激烈职位
    basic_data6: {
      jzbzd: []
    },
    // 报名人数十大热门职位
    basic_data7: {
      categories: [],
      series: [{}]
    },
    // 竞争比十大热门职位
    basic_data8: {
      categories: [],
      series: [{}]
    },
    // 报名人数十大冷门职位
    basic_data9: {
      categories: [],
      series: [{}]
    },
    // 竞争比十大热门职位
    basic_data10: {
      categories: [],
      series: [{}]
    },
    // 控制canvas宽高
    imageWidth: 300,
    imageHeigh1: 300,
    imageWidth1: 300,
    imageHeight1: 300,
    // 数据查询级联必要参数
    item01: [{
      id: "1_1",
      text: "请选择"
    }],
    item02: [{
      id: "2_1",
      text: "请选择"
    }],
    item03: [{
      id: "3_1",
      text: "请选择"
    }],
    item04: [{
      id: "4_1",
      text: "请选择"
    }],
    item01value: "",
    item02value: "",
    item03value: "",
    item04value: "",
    // 选岗查询级联必要参数
    item011: [{
      id: "1_1",
      text: "请选择"
    }],
    item021: [{
      id: "2_1",
      text: "请选择"
    }],
    item031: [{
      id: "3_1",
      text: "请选择"
    }],
    item041: [{
      id: "4_1",
      text: "请选择"
    }],
    item011value: "",
    item021value: "",
    item031value: "",
    item041value: "",
    jiansuo: true,
    jieguo: false,
    chaxunjg: '',
    cxlists: [],
    sclists: [],
    lookzw: [],
    lookzw1: [],
    collection: [],
    zwlist: true,
    zwlist1: true,
    zwlook: false,
    zwlook1: false,
    gonghao: '无',
    fenxiao: '无',
    laiyuan: `数据分析`,
    // 无岗位代码类型参数，是否参与
    file: '',
    bklx: '',
    // 无岗位代码类型参数，默认无岗位代码
    // hasDM:false,
    yl: 1,
    bookDetails_box: !1,
    isSydw: false,
    ready: 0,
    wangke: false,
    inputPhone: false,
  },
  onLoad: async function (options) {
    this.setData(await app.methods.myPhone()); // 获取本地存储手机号
    if(!this.data.myPhone) {
        await app.methods.getPhoneNumber()
        this.setData({
          isShowAuth: !0
        })
    }
    xhs.showShareMenu({
      shareTypes: 'normal',
    })
    xhs.showLoading({
      title: '数据加载中',
      mask: true
    })
    let links, jxOptions;
    if (options.scene) {
      options.scene = options.scene.replace(/%253D/g, ".");
      options.scene = options.scene.replace(/%2526/g, "-");
      jxOptions = await app.methods.getOPtions(options);
    }
    let id = options.scene ? jxOptions.id : options.id;
    options.id = id;
    links = await app.methods.getLink(id);
    options.fx = options.scene ? jxOptions.fx : options.fx;
    options.gh = options.scene ? jxOptions.gh : options.gh;
    options.zwid = links.zwid ? links.zwid : '';
    options.xm = links.xm ? links.xm : '';
    options.actid = Number(links.actid) ? Number(links.actid) : undefined;
    this.setData({
      options: options,
      actid: Number(options.actid) ? Number(options.actid) : undefined
    })
    if (options.xm != undefined) {
      if (options.xm.length > 0) {
        this.setData({
          xm: options.xm,
          xiangmu: options.xm,
        })
        let xm = options.xm
        if (xm.indexOf('sydw') >= 0) {
          this.setData({
            isSydw: true
          })
        }
      }
    }
    var query = xhs.createSelectorQuery();
    var query1 = xhs.createSelectorQuery();
    let aa1 = await this.getQuery(query, '.canvas2')
    let aa2 = await this.getQuery(query1, '.canvas3')
    // query1.select('.canvas3').boundingClientRect((rect) => {
    //   console.log(rect)
    //   this.setData({
    //     imageWidth1: rect.width,
    //     imageHeight1: rect.height,
    //   })
    // }).exec();
    this.setData(await app.methods.getIdentity(options)); // 获取个人身份信息
    if (this.data.getIdentity.crm) {
      options.wxh = this.data.getIdentity.crm
    } else {
      options.wxh = options.gh
    }
    this.setData(await app.methods.getWechat(options)); // 获取个人身份信息
    this.setData(await app.methods.guishudi(options)); // 获取归属地
    let fenbu = this.data.fenbu;
    let fenxiao = this.data.fenxiao;
    let getIdentity = this.data.getIdentity;
    getIdentity.fenbu = fenbu;
    getIdentity.fenxiao = fenxiao;
    getIdentity.zzname = this.data.zzname;
    getIdentity.zzid = this.data.zzid;
    getIdentity.erpdqm = this.data.erpdqm;
    this.setData({
      getIdentity: getIdentity
    })
    await this.getHdInfo()
    let data = {}
    this.data.fir == 'dq' ? data = {
      level: '1',
      'grfiled': 'diqu'
    } : data = {
      level: '1',
      'grfiled': 'bumen_name'
    }
    await this.onloadmr(this.data.cont, this.data.myPhone, this.data.actid)
    await this.level(data, 1, data.grfiled)
    this.data.myPhone == '' ? '' : this.setData(await app.methods.getphonestatusCX(this.data.myPhone, this.data.options.actid, 'chaxun'))
    this.thisMethod()
    if(this.data.isEnroll) {
      var date = new Date();
      let month = (date.getMonth() + 1).toString(); // 月份从0开始计数，因此需要加1并补零
      let day = date.getDate().toString();
      let hours = date.getHours().toString().padStart(2, '0');
      let minutes = date.getMinutes().toString().padStart(2, '0');
      this.setData({
        lastTime: `${month}月${day}日${hours}时${minutes}分`
      })
    }
    app.globalData.laiyuan = `${this.data.basic_data2.title}数据分析`
    xhs.showLoading({
      title: '加载完成！',
      mask: true
    })
    setTimeout(function () {
      xhs.hideLoading()
    }, 800)
    console.log(this.data)
  },
  getQuery(query, thisClass){
    return new Promise(resolve => {
      query.select(thisClass).boundingClientRect((rect) => {
        if(thisClass == '.canvas2') {
          this.setData({
            imageWidth: rect.width,
            imageHeight: rect.height,
          })
        } else {
          this.setData({
            imageWidth1: rect.width,
            imageHeight1: rect.height,
          })
        }
      }).exec(() => {
        resolve()
      });
    })
  },
  // 切换查看内容  
  async recoveryState(e) {
    if (e.currentTarget.id == 'on') {} else {
      if (e.currentTarget.dataset.num == 0) {
        // xhs.showLoading({
        //   title: '数据加载中',
        //   // mask: true
        // })
        this.setData({
          listId: 0,
          lists: [{
            'title': '数据一览',
            "zt": 'on'
          }, {
            'title': '数据查询',
            "zt": ''
          }, {
            'title': '职位收藏',
            "zt": ''
          }],
          // mrsjdb: '',
          // bmrssdlmzw: '',
          // bmrssdrmzw: '',
          // jzbsdlmzw: '',
          // jzbsdrmzw: '',
        })
        // await this.getHdInfo()
        // xhs.showLoading({
        //   title: '加载完成！',
        //   mask: true
        // })
        // setTimeout(function () {
        //   xhs.hideLoading()
        // }, 800)
      } else if (e.currentTarget.dataset.num == 1) {
        this.setData({
          listId: 1,
          lists: [{
            'title': '数据一览',
            "zt": ''
          }, {
            'title': '数据查询',
            "zt": 'on'
          }, {
            'title': '职位收藏',
            "zt": ''
          }],
        })
      } else if (e.currentTarget.dataset.num == 2) {
        if (this.data.myPhone == '') {
          if (app.globalData.PrivacyAuthorization) {
            this.setData({
              isShowAuth: !0,
              isPrivacyAuthorization: !0,
            })
          } else {
            this.setData({
              isShowAuth: !0,
              isPrivacyAuthorization: !1,
            })
          }
          return false
        }
        this.setData({
          listId: 2,
          lists: [{
            'title': '数据一览',
            "zt": ''
          }, {
            'title': '数据查询',
            "zt": ''
          }, {
            'title': '职位收藏',
            "zt": 'on'
          }]
        })
        this.mycollect()
      }
    }
  },
  // 获取活动信息
  async getHdInfo() {
    //截止时间
    var time = await this.time()
    if (time.status == 1) {
      this.setData({
        basic_data2: {
          lastTime: time.data.lastTime,
          title: time.data.title,
        },
        actid: Number(this.data.options.actid) ? Number(this.data.options.actid) : Number(time.data.actid),
        cont: Number(time.data.cont),
        fir: time.data.fir,
        bos: time.data.bos,
        k_name: time.data.k_name,
        k_url: time.data.k_url,
      })
      // 确定展示情况
      this.open(this.data.cont)
    }
    var sjzsz = false;
    var dss = 0;
    if (this.data.options.zwid == 396 || this.data.options.zwid == 397 || this.data.options.zwid == 398) {
      var bmrs = await this.bmrs()
      if (bmrs.status == 1) {
        sjzsz = true;
        dss = bmrs.data.dss;
      }
    }
    //总审核通过人数 总缴费数 总竞争比 平均竞争比
    var subao = await this.subao()
    if (subao.status == 1) {
      if (sjzsz == true) {
        this.setData({
          basic_data3: {
            jhs: subao.data.jhs,
            tgs: subao.data.tgs,
            jfs: subao.data.jfs,
            agv_jzb: subao.data.agv_jzb,
            dss: dss,
          }
        })
      } else {
        this.setData({
          basic_data3: {
            jhs: subao.data.jhs,
            tgs: subao.data.tgs,
            jfs: subao.data.jfs,
            agv_jzb: subao.data.agv_jzb,
          }
        })
      }
      let jzb = "'" + this.data.basic_data3.agv_jzb + "'"
      if (jzb.indexOf('.0') >= 0) {
        this.data.basic_data3.agv_jzb = jzb.substring(0, jzb.length - 2)
      }
    } else {
      // console.log(subao.info);
    }
    //每日报名数据 图表
    var everydayDate = await this.everydayDate()
    // console.log(everydayDate)
    if (everydayDate.status == 1) {
      if (everydayDate.data.length > 0) {
        let categories1 = [];
        let series1 = [];
        if (this.data.bos == 'b') {
          var seriesObj1 = {
            name: this.data.cont != 9 ? '报名人数' : '缴费人数',
            data: []
          };
        } else if (this.data.bos == 's') {
          var seriesObj1 = {
            name: this.data.cont != 9 ? '审核通过人数' : '缴费人数',
            data: []
          };
        }
        if (this.data.isjfs) {
          var seriesObj2 = {
            name: this.data.cont == 8 ? '报名人数' : '缴费人数',
            data: []
          };
        }
        for (var i = 0; i < everydayDate.data.length; i++) {
          categories1[i] = everydayDate.data[i].riqi;
          seriesObj1.data[i] = everydayDate.data[i].tgs;
          if (this.data.isjfs) {
            seriesObj2.data[i] = everydayDate.data[i].jfs;
          }
        }
        series1.push(seriesObj1)
        if (this.data.isjfs) {
          series1.push(seriesObj2)
        }
        this.setData({
          basic_data4: {
            categories: categories1,
            series: series1
          },
          mrbmsj: true
        })
        // 每日报名数据对比
        await this.zxt('mrsjdb', this.data.basic_data4.categories, this.data.basic_data4.series, this.data.imageWidth, 300)
        // var mrsjdb = await this.draw('mrsjdb', this.data.imageWidth, this.data.imageHeight)
        // console.log(mrsjdb)
        // this.setData({
        //   mrsjdb: mrsjdb
        // })
      } else {
        this.setData({
          mrbmsj: false
        })
      }
    } else {
      console.log(everydayDate.info);
    }
    //报名人数最多招考单位(tgs)
    var enrollmentMore = await this.getDate('tgs', 'desc')
    if (enrollmentMore.status == 1) {
      this.setData({
        basic_data5: {
          tgs: enrollmentMore.data[0].tgs,
          diqu: enrollmentMore.data[0].diqu,
          bumen_name: enrollmentMore.data[0].bumen_name,
          yongren_danwei: enrollmentMore.data[0].yongren_danwei,
          gangwei_name: enrollmentMore.data[0].gangwei_name,
        }
      })
      let categories1 = [];
      let series1;
      if (this.data.bos == 'b') {
        series1 = [{
          name: this.data.cont != 9 ? '报名人数' : '缴费人数',
          data: []
        }];
      } else if (this.data.bos == 's') {
        series1 = [{
          name: this.data.cont != 9 ? '审核通过人数' : '缴费人数',
          data: []
        }];
      }
      for (var i = 0; i < enrollmentMore.data.length; i++) {
        if (!enrollmentMore.data[i].diqu) {
          enrollmentMore.data[i].diqu = ''
        }
        if (!enrollmentMore.data[i].bumen_name) {
          enrollmentMore.data[i].bumen_name = ''
        }
        if (!enrollmentMore.data[i].yongren_danwei) {
          enrollmentMore.data[i].yongren_danwei = ''
        }
        if (!enrollmentMore.data[i].gangwei_name) {
          enrollmentMore.data[i].gangwei_name = ''
        }
        categories1[i] = enrollmentMore.data[i].bumen_name + enrollmentMore.data[i].yongren_danwei + enrollmentMore.data[i].gangwei_name;
        series1[0].data[i] = enrollmentMore.data[i].tgs;
      }
      this.setData({
        basic_data7: {
          categories: categories1,
          series: series1
        }
      })
      // 报名人数最多招考单位
      await this.zzt('bmrssdrmzw', this.data.basic_data7.categories, this.data.basic_data7.series, this.data.imageWidth1, 600, '人')
      // var bmrssdrmzw = await this.draw('bmrssdrmzw', this.data.imageWidth1, this.data.imageHeight2)
      // this.setData({
      //   bmrssdrmzw: bmrssdrmzw
      // })
    } else {
      console.log(enrollmentMore.info);
    }
    //竞争最激烈招考单位(jzb)
    var competeMore = await this.getDate('jzb', 'desc')
    if (competeMore.status == 1) {
      this.setData({
        basic_data6: {
          jzb: competeMore.data[0].jzb,
          diqu: competeMore.data[0].diqu,
          bumen_name: competeMore.data[0].bumen_name,
          yongren_danwei: competeMore.data[0].yongren_danwei,
          gangwei_name: competeMore.data[0].gangwei_name,
        }
      })
      let jzb1 = Number(competeMore.data[0].jzb);
      let jzb2 = Number(competeMore.data[0].tgs) / Number(competeMore.data[0].jhs);
      let jzb3 = Number(competeMore.data[0].jfs) / Number(competeMore.data[0].jhs);
      jzb1.toFixed(2) == jzb2.toFixed(2) ? this.setData({
        jsMethod: 'tgs',
        agv_jzb: (Number(this.data.basic_data3.tgs) / Number(this.data.basic_data3.jhs)).toFixed(1)
      }) : jzb1.toFixed(2) == jzb3.toFixed(2) ? this.setData({
        jsMethod: 'jfs',
        agv_jzb: (Number(this.data.basic_data3.jfs) / Number(this.data.basic_data3.jhs)).toFixed(1)
      }) : this.setData({
        jsMethod: '',
        agv_jzb: this.data.basic_data3.agv_jzb
      })
      if (this.data.basic_data6.jzb.indexOf('.0') >= 0) {
        let basic_data6_jzb_data = this.data.basic_data6.jzb.substring(0, this.data.basic_data6.jzb.length - 2)
        let basic_data6_jzb = 'basic_data6.jzb'
        this.setData({
          [basic_data6_jzb]: basic_data6_jzb_data,
        })
      }
      let categories1 = [];
      let series1 = [{
        name: '比例',
        data: []
      }];
      for (var i = 0; i < competeMore.data.length; i++) {
        if (!competeMore.data[i].diqu) {
          competeMore.data[i].diqu = ''
        }
        if (!competeMore.data[i].bumen_name) {
          competeMore.data[i].bumen_name = ''
        }
        if (!competeMore.data[i].yongren_danwei) {
          competeMore.data[i].yongren_danwei = ''
        }
        if (!competeMore.data[i].gangwei_name) {
          competeMore.data[i].gangwei_name = ''
        }
        categories1[i] = competeMore.data[i].bumen_name + competeMore.data[i].yongren_danwei + competeMore.data[i].gangwei_name;
        let thisjzb = competeMore.data[i].jzb
        if (thisjzb.indexOf('.0') >= 0) {
          thisjzb = thisjzb.substring(0, thisjzb.length - 2)
        }
        series1[0].data[i] = thisjzb;
      }
      this.setData({
        basic_data8: {
          categories: categories1,
          series: series1
        }
      })
      // 竞争比数据对比
      this.zzt('jzbsdrmzw', this.data.basic_data8.categories, this.data.basic_data8.series, this.data.imageWidth1, 600, ':1')
      // var jzbsdrmzw = await this.draw('jzbsdrmzw', this.data.imageWidth1, this.data.imageHeight2)
      // this.setData({
      //   jzbsdrmzw: jzbsdrmzw
      // })
    } else {
      console.log(competeMore.info);
    }
    //报名人数最少招考单位(tgs)
    var enrollmentless = await this.getDate('tgs', 'asc')
    if (enrollmentless.status == 1) {
      let categories1 = [];
      let series1;
      if (this.data.bos == 'b') {
        series1 = [{
          name: this.data.cont != 9 ? '报名人数' : '缴费人数',
          data: []
        }];
      } else if (this.data.bos == 's') {
        series1 = [{
          name: this.data.cont != 9 ? '审核通过人数' : '缴费人数',
          data: []
        }];
      }
      for (var i = 0; i < enrollmentless.data.length; i++) {
        if (!enrollmentless.data[i].diqu) {
          enrollmentless.data[i].diqu = ''
        }
        if (!enrollmentless.data[i].bumen_name) {
          enrollmentless.data[i].bumen_name = ''
        }
        if (!enrollmentless.data[i].yongren_danwei) {
          enrollmentless.data[i].yongren_danwei = ''
        }
        if (!enrollmentless.data[i].gangwei_name) {
          enrollmentless.data[i].gangwei_name = ''
        }
        categories1[i] = enrollmentless.data[i].bumen_name + enrollmentless.data[i].yongren_danwei + enrollmentless.data[i].gangwei_name;
        series1[0].data[i] = enrollmentless.data[i].tgs;
      }
      this.setData({
        basic_data9: {
          categories: categories1,
          series: series1
        }
      })
      // 报名人数最少招考单位
      this.zzt('bmrssdlmzw', this.data.basic_data9.categories, this.data.basic_data9.series, this.data.imageWidth1, 600, '人')
      // var bmrssdlmzw = await this.draw('bmrssdlmzw', this.data.imageWidth1, this.data.imageHeight2)
      // this.setData({
      //   bmrssdlmzw: bmrssdlmzw
      // })
    } else {
      console.log(enrollmentless.info);
    }
    //竞争最激烈招考单位(jzb)
    var competeless = await this.getDate('jzb', 'asc')
    if (competeless.status == 1) {
      let categories1 = [];
      let series1 = [{
        name: '比例',
        data: []
      }];
      for (var i = 0; i < competeless.data.length; i++) {
        if (!competeless.data[i].diqu) {
          competeless.data[i].diqu = ''
        }
        if (!competeless.data[i].bumen_name) {
          competeless.data[i].bumen_name = ''
        }
        if (!competeless.data[i].yongren_danwei) {
          competeless.data[i].yongren_danwei = ''
        }
        if (!competeless.data[i].gangwei_name) {
          competeless.data[i].gangwei_name = ''
        }
        categories1[i] = competeless.data[i].bumen_name + competeless.data[i].yongren_danwei + competeless.data[i].gangwei_name;
        let thisjzb = competeless.data[i].jzb
        if (thisjzb.indexOf('.0') >= 0) {
          thisjzb = thisjzb.substring(0, thisjzb.length - 2)
        }
        series1[0].data[i] = thisjzb;
      }
      this.setData({
        basic_data10: {
          categories: categories1,
          series: series1
        }
      })
      // 竞争比数据对比
      this.zzt('jzbsdlmzw', this.data.basic_data10.categories, this.data.basic_data10.series, this.data.imageWidth1, 600, ':1')
      // var jzbsdlmzw = await this.draw('jzbsdlmzw', this.data.imageWidth1, this.data.imageHeight2)
      // this.setData({
      //   jzbsdlmzw: jzbsdlmzw
      // })
    } else {
      console.log(competeless.info);
    }
  },
  // 柱状图
  async zzt(canvasId, categories, series, width, height, yAxis1) {
    return new Promise((resolve) => {
      new Charts({
        canvasId: canvasId,
        dataPointShape: false,
        type: 'column',
        categories: categories,
        series: series,
        animation: false,
        yAxis: {
          format: function (val) {
            return val + yAxis1;
          },
        },
        xAxis: {
          disableGrid: true,
        },
        width: width,
        height: height,
        dataLabel: true,
        extra: {
          column: {
            width: 40 //柱的宽度
          }
        }
      });
      resolve()
    })
  },
  // 折线图
  async zxt(canvasId, categories, series, width, height) {
    return new Promise((resolve) => {
      new Charts({
        canvasId: canvasId,
        dataPointShape: "circle",
        animation: false,
        type: 'line',
        extra: {
          lineStyle: 'curve' //线条的形状（弧形）
        },
        categories: categories,
        series: series,
        yAxis: {
          // title: this.data.cont != 9 ? '报名人数(人)' : '缴费人数(人)',
          title: '人数',
          format: function (val) {
            return val.toFixed(0);
          },
          fontColor: "red",
          titleFontColor: "red",
          min: 0,
        },
        width: width,
        height: height,
        dataLabel: true
      });
      resolve()
    })
  },
  // 获取时间
  async time() {
    return new Promise((resolve, reject) => {
      hbappRequest({
        url: `/hbqt/web/index.php/Skzw/indexnews/getlastime?zwid=${this.data.options.zwid}&callback=&`,
        method: 'GET',
        dataType: 'jsonp',
        data: '',
      }).then(res => {
        let newStr = app.methods.getAPIReturn(res);
        if (newStr.status == 1) {
          resolve(newStr)
        } else {
          reject()
        }
      }).catch(err => {
        console.log(err)
        reject()
      })
    })
  },
  //总审核通过人数 总缴费数 总竞争比 平均竞争比
  async subao() {
    return new Promise((resolve, reject) => {
      hbappRequest({
        url: `/hbqt/web/index.php/Skzw/indexnews/getcount_zshu?zwid=${this.data.options.zwid}&callback=&`,
        method: 'GET',
        dataType: 'jsonp',
        data: {},
        success: ((res) => {
        })
      }).then(res => {
        let newStr = app.methods.getAPIReturn(res);
        // console.log(newStr)
        if (newStr.status == 1) {
          resolve(newStr)
        } else {
          reject()
        }
      }).catch(err => {
        console.log(err)
        reject()
      })
    })
  },
  // 石家庄市直获取报名人数
  async bmrs() {
    return new Promise((resolve, reject) => {
      hbappRequest({
        url: `/hbqt/web/index.php/Skzw/indexnews/getcount_zshu2?zwid=${this.data.options.zwid}&callback=&`,
        method: 'GET',
        dataType: 'jsonp',
        data: {},
      }).then(res => {
        let newStr = app.methods.getAPIReturn(res);
        // console.log(newStr)
        if (newStr.status == 1) {
          resolve(newStr)
        } else {
          reject()
        }
      }).catch(err => {
        console.log(err)
        reject()
      })
    })
  },
  //每日报名数据 图表
  async everydayDate() {
    return new Promise((resolve, reject) => {
      hbappRequest({
        url: `/hbqt/web/index.php/Skzw/indexnews/everyday_bmrs_newinfos?zwid=${this.data.options.zwid}&callback=&`,
        method: 'GET',
        dataType: 'jsonp',
        data: {},
      }).then(res => {
        let newStr = app.methods.getAPIReturn(res);
        // console.log(newStr)
        if (newStr.status == 1) {
          resolve(newStr)
        } else {
          reject()
        }
      }).catch(err => {
        console.log(err)
        reject()
      })
    })
  },
  // 数据概览中获取数据方法
  async getDate(order, type) {
    return new Promise((resolve) => {
      hbappRequest({
        url: `/hbqt/web/index.php/Skzw/indexnews/position_ranking?zwid=${this.data.options.zwid}&callback=&`,
        method: 'GET',
        dataType: 'jsonp',
        data: {
          'order': order,
          'type': type,
          'limits': 10
        }, //order排序值,type(desc降序,asc升序),limits条数
      }).then(res => {
        let newStr = app.methods.getAPIReturn(res);
        // console.log(newStr)
        if (newStr.status == 1) {
          resolve(newStr)
        } else {
          reject()
        }
      }).catch(err => {
        console.log(err)
        reject()
      })
    })
  },
  // 将canvas转成image
  async draw(canvasId, imageWidth, imageHeight) {
    console.log(canvasId, imageWidth, imageHeight)
    return new Promise((resolve) => {
      xhs.canvasToTempFilePath({
        width: imageWidth,
        height: imageHeight,
        canvasId: canvasId,
        success(res) {
          console.log(res)
          resolve(res.tempFilePath)
        },
        fail(err) {
          console.log(err)
          resolve()
        },
        complete(err) {
          console.log(err)
          resolve()
        }
      })
      // setTimeout(function () {
        
      // }, 400)
    })
  },
  // 监听手机号
  async watchBack(value) {
    if (value && value.myPhone) {
      this.setData({
        myPhone: value.myPhone
      })
      this.setData(await app.methods.getphonestatusCX(this.data.myPhone, this.data.actid, 'chaxun'))
      // console.log(this.data)
      this.thisMethod()
    }
  },
  // 该怎么就怎么
  async thisMethod() {
    if (!this.data.user) {
      if (this.data.isSydw && this.data.myPhone != '') {
        this.setData({
          bookDetails_box: 1
        })
      } else if (!this.data.isSydw && this.data.myPhone) {
        await app.methods.registerCX(this.data.myPhone, this.data.actid, `${this.data.basic_data2.title}数据分析`, this.data.isSydw, this.data.getIdentity, '', '', '', 'chaxun')
      }
    } else {
      if ((this.data.user.user.gwlb == '' || this.data.user.user.gwlb == 'null' || !this.data.user.user.gwlb) && this.data.isSydw) {
        this.setData({
          bookDetails_box: 1
        })
      } else {
        await app.methods.updateuserCX(this.data.myPhone, this.data.actid, `${this.data.basic_data2.title}数据分析`, this.data.isSydw, this.data.getIdentity, this.data.user.user.gwlb, '', 'chaxun', '', this.data.user.user)
      }
    }
  },
  // 选择岗位
  async choiceGw(e) {
    console.log(e);
    if (!this.data.user) {
      await app.methods.registerCX(this.data.myPhone, this.data.actid, `${this.data.basic_data2.title}数据分析`, this.data.isSydw, this.data.getIdentity, e.currentTarget.dataset.gwlb, '', '', 'chaxun')
      this.setData({
        bookDetails_box: !1
      })
    } else {
      await app.methods.updateuserCX(this.data.myPhone, this.data.actid, `${this.data.basic_data2.title}数据分析`, this.data.isSydw, this.data.getIdentity, e.currentTarget.dataset.gwlb, '', 'chaxun', '', this.data.user.user)
      this.setData({
        bookDetails_box: !1
      })
    }
  },
  // 数据一览---页面加载后选岗信息部分
  async onloadmr(cont, myPhone, actid) {
    // if(this.data.myPhone == '') {
    //     if(this.data.PrivacyAuthorization) {
    //         this.setData({
    //             isShowAuth: !0,
    //             isPrivacyAuthorization: !0,
    //         })
    //     } else {
    //         this.setData({
    //             isShowAuth: !0,
    //             isPrivacyAuthorization: !1,
    //         })
    //     }
    //     return false
    // }
    (((this.data.cont == 0) || (this.data.cont == 1) || (this.data.cont == 3) || (this.data.cont == 4) || (this.data.cont == 6) || (this.data.cont == 7)) ? await this.getjlinfo(this.data.myPhone, this.data.actid) : '')
  },
  // 可选岗状态
  async getjlinfo(myPhone, actid) {
    // console.log(myPhone,actid)
    return new Promise((resolve) => {
      zg99Request({
        url: `/index/chaxun/getjlinfo?actid=${actid}?callback=&`,
        method: 'GET',
        dataType: 'jsonp',
        data: {
          phone: myPhone,
          Limits: 200,
          shijian: Date.parse(new Date()) / 1000
        },
      }).then(res => {
        let newStr = app.methods.getAPIReturn(res);
        // console.log(newStr)
        if (newStr.status == 1) {
          let user = newStr.lists[0]
          // 查询记录表是否已报名(已报名)
          let isEnroll = ((Number(this.data.cont) == 0) || (Number(this.data.cont) == 3) || (Number(this.data.cont) == 6)) ? true : false
          this.setData({
            isgongbu: false,
            isEnroll: isEnroll,
          })
          if ((Number(this.data.cont) == 0) || (Number(this.data.cont) == 3) || (Number(this.data.cont) == 6)) {
            this.getjlcount(actid, this.data.fir == 'dq' ? user.item01 : '', user.item02, user.item03, user.item04, user.item05, user.item06)
          }
        } else {
          this.setData({
            isgongbu: true,
          })
        }
        resolve()
      }).catch(err => {
        console.log(err)
        resolve()
      })
    })
  },
  // 展示出所选岗位
  async getjlcount(actid, item01, item02, item03, item04, item05, item06) {
    // console.log(actid, item01, item02, item03, item04, item05, item06)
    return new Promise((resolve) => {
      zg99Request({
        url: `/index/chaxun/getjlcount?actid=${actid}&callback=&shijian=${Date.parse(new Date()) / 1e3}`,
        method: 'GET',
        dataType: 'jsonp',
        data: {
          item01: item01,
          item02: item02,
          item03: item03,
          item04: item04,
          item05: item05,
          item06: item06,
        },
      }).then(res => {
        let newStr1 = app.methods.getAPIReturn(res);
        // console.log(newStr1)
        this.setData({
          users: {
            item01: item01,
            item02: item02,
            item03: item03,
            item04: item04,
            item05: item05,
            item06: item06,
            total: newStr1.total,
            jzb: (Number(newStr1.total / item06)).toFixed(2),
          }
        })
        resolve()
      }).catch(err => {
        console.log(err)
        resolve()
      })
    })
  },
  // 级联获取数据
  async level(data, level, grfiled) {
    return new Promise((resolve) => {
      hbappRequest({
        url: `/hbqt/web/index.php/Skzw/indexnews/getlevel_list?zwid=${this.data.options.zwid}&callback=&`,
        method: 'GET',
        dataType: 'jsonp',
        data: data,
      }).then(res => {
        let newStr = app.methods.getAPIReturn(res);
        // console.log(newStr)
        var newArr = [];
        for (var i = 0; i < newStr.data.length; i++) {
          var newObj = {};
          newObj.id = level + '_' + i;
          newObj.text = newStr.data[i][grfiled];
          newArr.push(newObj)
        }
        let a = 'item0' + level;
        let b = 'item0' + level + '1';
        this.setData({
          [a]: newArr,
          [b]: newArr,
        })
        if (level == 1) {
          this.setData({
            thisDate: newStr.data[0]
          })
        }
        resolve()
      }).catch(err => {
        console.log(err)
        resolve()
      })
    })
  },
  // 数据查询级联部分
  m_select_touch: function (e) {
    // console.log(e)
    let data = {};
    let stype = e.detail.stype;
    let level = e.currentTarget.dataset.level;
    let a = 'item0' + stype + 'value';
    this.setData({
      [a]: e.detail.selectText
    })
    let grfiled = '';
    let onefiled = this.data.fir == 'dq' ? 'diqu' : 'bumen_name';
    let twofiled = this.data.fir == 'dq' ? 'bumen_name' : 'yongren_danwei';
    let threefiled = this.data.fir == 'dq' ? 'yongren_danwei' : 'gangwei_name';
    if (level == 1) {
      grfiled = this.data.fir == 'dq' ? 'bumen_name' : 'yongren_danwei';
      data = {
        level: '2',
        'grfiled': grfiled,
        onefiled: onefiled,
        onetext: this.data[a]
      }
    } else if (level == 2) {
      grfiled = this.data.fir == 'dq' ? 'yongren_danwei' : 'gangwei_name';
      data = {
        level: '3',
        'grfiled': grfiled,
        onefiled: onefiled,
        onetext: stype == 2 ? this.data.item01value : this.data.item011value,
        twofiled: twofiled,
        twotext: this.data[a]
      }
    } else if (level == 3) {
      grfiled = this.data.fir == 'dq' ? 'gangwei_name' : 'gangwei_code';
      data = {
        level: '4',
        'grfiled': grfiled,
        onefiled: onefiled,
        onetext: stype == 3 ? this.data.item01value : this.data.item011value,
        twofiled: twofiled,
        twotext: stype == 3 ? this.data.item02value : this.data.item021value,
        threefiled: threefiled,
        threetext: this.data[a]
      }
    }
    if (level != 4) {
      this.level(data, Number(level) + 1, grfiled)
    }
  },
  // 检索岗位
  async clickfn() {
    this.setData(await app.methods.getphonestatusCX(this.data.myPhone, this.data.actid, 'chaxun'))
    await this.thisMethod()
    let data = {};
    this.data.fir == 'dq' ? data = {
      phone: this.data.myPhone,
      diqu: this.data.item01value,
      bumen_name: this.data.item02value,
      yongren_danwei: this.data.item03value,
      gangwei_name: this.data.item04value,
      limits: '200'
    } : data = {
      phone: this.data.myPhone,
      bumen_name: this.data.item01value,
      yongren_danwei: this.data.item02value,
      gangwei_name: this.data.item03value,
      gangwei_code: this.data.item04value,
      limits: '200'
    }
    hbappRequest({
      url: `/hbqt/web/index.php/Skzw/indexnews/getsearch_list?zwid=${this.data.options.zwid}?callback=&shijian=${Date.parse(new Date())}`,
      method: 'GET',
      dataType: 'jsonp',
      data: data,
    }).then(res => {
      let newStr = app.methods.getAPIReturn(res);
      // console.log(newStr)
      if (newStr.msg != '暂无数据') {
        let jsdata = newStr.data
        var newObj = []
        for (var i = 0; i < jsdata.length; i++) {
          let index = i;
          let thisjzb = jsdata[index].jzb
          if (thisjzb.indexOf('.0') >= 0) {
            thisjzb = thisjzb.substring(0, thisjzb.length - 2)
            jsdata[index].jzb = thisjzb
          }
          newObj.push(jsdata[index])
        }
        this.setData({
          jiansuo: false,
          jieguo: true,
          chaxunjg: newObj.length,
          cxlists: newObj,
        })
        xhs.hideLoading()
        xhs.showToast({
          title: '数据查询成功!',
          icon: 'success',
          duration: 2000
        })
      } else {
        xhs.hideLoading()
        xhs.showToast({
          title: '未匹配到可报考岗位，请重新填写条件后查询!',
          icon: 'none',
          duration: 2000
        })
      }
    }).catch(err => {
      console.log(err)
    })
  },
  // 记录报名岗位
  async clickfn1() {
    if (this.data.item011value == '') {
      xhs.showToast({
        title: '请选择第一项',
        icon: 'none',
        duration: 2000
      })
      return false
    }
    if (this.data.item021value == '') {
      xhs.showToast({
        title: '请选择第二项',
        icon: 'none',
        duration: 2000
      })
      return false
    }
    if (this.data.item031value == '') {
      xhs.showToast({
        title: '请选择第三项',
        icon: 'none',
        duration: 2000
      })
      return false
    }
    if (this.data.item041value == '') {
      xhs.showToast({
        title: '请选择第四项',
        icon: 'none',
        duration: 2000
      })
      return false
    }
    let jhs = 0;
    (((this.data.cont == 0) || (this.data.cont == 1) || (this.data.cont == 3) || (this.data.cont == 4) || (this.data.cont == 6) || (this.data.cont == 7)) ? await this.getsearch_list(this.data.actid, this.data.options.zwid) : '')
  },
  // 检索职位
  async getsearch_list(actid, zwid) {
    return new Promise((resolve) => {
        let data = {}
        this.data.fir == 'dq' ? data = {
          phone: this.data.myPhone,
          diqu: this.data.item011value,
          bumen_name: this.data.item021value,
          yongren_danwei: this.data.item031value,
          gangwei_name: this.data.item041value,
          limits: '200'
        } : data = {
          phone: this.data.myPhone,
          bumen_name: this.data.item011value,
          yongren_danwei: this.data.item021value,
          gangwei_name: this.data.item031value,
          gangwei_code: this.data.item041value,
          limits: '200'
        }
        hbappRequest({
          url: `/hbqt/web/index.php/Skzw/indexnews/getsearch_list?zwid=${zwid}&callback=&`,
          method: 'GET',
          dataType: 'jsonp',
          data: data,
        }).then(res => {
          let newStr = app.methods.getAPIReturn(res);
          // console.log(newStr)
          resolve(newStr)
        }).catch(err => {
          console.log(err)
        })
      })
      .then((res) => {
        let data = {};
        this.data.fir == 'dq' ? data = {
          'phone': this.data.myPhone,
          'item01': this.data.item011value,
          'item02': this.data.item021value,
          'item03': this.data.item031value,
          'item04': this.data.item041value,
          'item05': res.data[0].gangwei_code,
          'item06': res.data[0].jhs,
          shijian: Date.parse(new Date()) / 1e3
        } : data = {
          phone: this.data.myPhone,
          // 'item01': 'null',
          'item02': this.data.item011value,
          'item03': this.data.item021value,
          'item04': this.data.item031value,
          'item05': this.data.item041value,
          'item06': res.data[0].jhs,
          shijian: Date.parse(new Date()) / 1e3
        }
        zg99Request({
          url: `/index/chaxun/writelogs?actid=${actid}&callback=&`,
          method: 'GET',
          dataType: 'jsonp',
          data: data,
        }).then(ress => {
          let newStr = app.methods.getAPIReturn(ress);
          // console.log(newStr)
          xhs.showModal({
            title: '提示',
            showCancel: false,
            content: newStr.msg,
          })
          this.getjlinfo(this.data.myPhone, this.data.actid)
        }).catch(err => {
          console.log(err)
        })
      })
  },
  // 收藏或取消收藏岗位
  async collect(e) {
    if (this.data.myPhone == '') {
      if (app.globalData.PrivacyAuthorization) {
        this.setData({
          isShowAuth: !0,
          isPrivacyAuthorization: !0,
        })
      } else {
        this.setData({
          isShowAuth: !0,
          isPrivacyAuthorization: !1,
        })
      }
      return false
    }
    let methods = e.currentTarget.dataset.is_collect == 0 ? 'getcollect_add' : 'getcollect_del';
    hbappRequest({
      url: `/hbqt/web/index.php/Skzw/indexnews/${methods}?zwid=${this.data.options.zwid}?callback=&shijian=${Date.parse(new Date())}`,
      method: 'post',
      dataType: 'json',
      data: {
        'phone': this.data.myPhone,
        'mid': e.currentTarget.dataset.id,
        'gangwei_code': e.currentTarget.dataset.gangwei_code
      },
    }).then(res => {
      let newStr = app.methods.getAPIReturn(res);
      // console.log(newStr)
      this.clickfn()
      this.mycollect()
    }).catch(err => {
      console.log(err)
    })
  },
  // 获取收藏职位信息
  async mycollect() {
    hbappRequest({
      url: `/hbqt/web/index.php/Skzw/indexnews/getcollect_list?zwid=${this.data.options.zwid}?callback=&shijian=${Date.parse(new Date())}`,
      method: 'post',
      dataType: 'json',
      data: {
        'phone': this.data.myPhone
      }, //收藏者手机号
    }).then(res => {
      let newStr = app.methods.getAPIReturn(res);
      // console.log(newStr)
      this.setData({
        sclists: newStr.data
      })
    }).catch(err => {
      console.log(err)
    })
  },
  // 修改条件
  changetj: function () {
    this.setData({
      jiansuo: true,
      jieguo: false,
      zwlist1: true,
      zwlook1: false,
      item01value: "",
      item02value: "",
      item03value: "",
      item04value: "",
      everyday1: '',
    })
  },
  // 数据查询查看数据
  async lookeveryday(event) {
    return new Promise((resolve) => {
        let a = event.currentTarget.dataset.type == 'chaxun' ? 'lookzw1' : 'lookzw'
        this.setData({
          [a]: event.currentTarget.dataset.lookzw
        })
        hbappRequest({
          url: `/hbqt/web/index.php/Skzw/indexnews/everyday_bmrs_newinfos?zwid=${this.data.options.zwid}&callback=&`,
          method: 'GET',
          dataType: 'jsonp',
          data: {
            'gangwei_code': event.currentTarget.dataset.gangwei_code
          },
          success: ((res) => {
          })
        }).then(res => {
          let newStr = app.methods.getAPIReturn(res);
          // console.log(newStr)
          if (newStr.status == 1) {
            if (newStr.data.length > 0) {
              var categories1 = [];
              var series1 = [];
              var seriesObj1 = {
                name: this.data.cont != 9 ? '审核通过人数' : '缴费人数',
                data: []
              };
              if (this.data.isjfs) {
                var seriesObj2 = {
                  name: this.data.cont == 8 ? '报名人数' : '缴费人数',
                  data: []
                };
              }
              for (var i = 0; i < newStr.data.length; i++) {
                categories1[i] = newStr.data[i].riqi;
                seriesObj1.data[i] = newStr.data[i].tgs;
                if (this.data.isjfs) {
                  seriesObj2.data[i] = newStr.data[i].jfs;
                }
              }
              series1.push(seriesObj1)
              if (this.data.isjfs) {
                series1.push(seriesObj2)
              }
              let b = event.currentTarget.dataset.type == 'chaxun' ? 'basic_data12' : 'basic_data11';
              let c = event.currentTarget.dataset.type == 'chaxun' ? 'zwlist1' : 'zwlist';
              let d = event.currentTarget.dataset.type == 'chaxun' ? 'zwlook1' : 'zwlook';
              let e = event.currentTarget.dataset.type == 'chaxun' ? 'everyday1' : 'everyday';
              this.setData({
                [b]: {
                  categories: categories1,
                  series: series1
                },
                mrbmsj: true,
                [c]: false,
                [d]: true,
              })
              let thisArr = [];
              thisArr[0] = e;
              thisArr[1] = categories1;
              thisArr[2] = series1;
              resolve(thisArr)
            } else {
              this.setData({
                mrbmsj: false
              })
              resolve()
            }
          } else {
            console.log(newStr.info);
            resolve()
          }
        }).catch(err => {
          console.log(err)
          resolve()
        })
      })
      .then(async (res) => {
        // console.log(res)
        // 每日报名数据对比
        await this.zxt(res[0], res[1], res[2], this.data.imageWidth, 300)
        // let data = await this.draw(res[0], this.data.imageWidth, this.data.imageHeight)
        // let name = res[0]
        // this.setData({
        //   [name]: data
        // })
      })
  },
  back: function () {
    this.setData({
      zwlist: true,
      zwlook: false,
      everyday: '',
    })
  },
  back1: function () {
    this.setData({
      zwlist1: true,
      zwlook1: false,
      everyday1: '',
    })
  },
  // 验证是否需要展示默认板块
  open: function (a) {
    switch (a) {
      case 0:
        this.setData({
          isshow: true,
          isgongbu: true,
          isjfs: false,
          isEnroll: false,
        })
        break;
      case 1:
        this.setData({
          isshow: true,
          isgongbu: true,
          isjfs: false,
          isEnroll: false,
        })
        break;
      case 2:
        this.setData({
          isshow: false,
          isgongbu: false,
          isjfs: true,
          isEnroll: false,
        })
        break;
      case 3:
        this.setData({
          isshow: false,
          isgongbu: true,
          isjfs: true,
          isEnroll: false,
        })
        break;
      case 4:
        this.setData({
          isshow: false,
          isgongbu: true,
          isjfs: true,
          isEnroll: false,
        })
        break;
      case 5:
        this.setData({
          isshow: false,
          isgongbu: false,
          isjfs: false,
          isEnroll: false,
        })
        break;
      case 6:
        that.setData({
          isshow: false,
          isgongbu: true,
          isjfs: false,
          isEnroll: false,
        })
        break;
      case 7:
        this.setData({
          isshow: false,
          isgongbu: true,
          isjfs: false,
          isEnroll: false,
        })
        break;
      case 8:
        this.setData({
          isshow: false,
          isgongbu: false,
          isjfs: true,
          isEnroll: false,
        })
        break;
    }
  },

  // 模拟报名情况下查看其他数据
  goOther() {
    this.setData({
      listId: 1,
      lists: [{
        'title': '数据一览',
        "zt": ''
      }, {
        'title': '数据查询',
        "zt": 'on'
      }, {
        'title': '职位收藏',
        "zt": ''
      }],
    })
  },
  async user_login(e){
      if(typeof e.detail == 'boolean') {
          this.setData({
              isShowAuth: e.detail
          })
      } else {
          this.setData({
              myPhone: e.detail
          })
          this.setData(await app.methods.getphonestatusCX(this.data.myPhone, this.data.actid, 'chaxun'))
          this.thisMethod()
      }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let { fx = 'hbwtb', gh = 'zcj37368', id } = this.data.options;
    return {
      title: this.data.k_name ? this.data.k_name : this.data.basic_data2.title,
      path: `/pages/fx/fx?id=${id}&fx=${fx}&gh=${gh}`,
      imageUrl: this.data.k_url ? this.data.k_url : '',
    }
  }
})